package com.bw.z.mvp.presenter;

import com.blankj.utilcode.util.LogUtils;
import com.bw.z.mvp.model.entity.BaseEntity;
import com.bw.z.mvp.base.presenter.BasePresenter;
import com.bw.z.mvp.contract.RegisterContract;
import com.bw.z.mvp.model.entity.RegisterEntity;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.schedulers.Schedulers;

public class RegisterPresenter extends BasePresenter<RegisterContract.registerModel, RegisterContract.registerView> {
    @Inject
    public RegisterPresenter(RegisterContract.registerModel registerModel, RegisterContract.registerView registerView) {
        super(registerModel, registerView);
    }

    public void getRegisterData(int name, String pwd) {
        Map<String, Object> map = new HashMap<>();
        map.put("phone", name);
        map.put("pwd", pwd);
        m.requestRegister(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this::onNext);
    }

    @Override
    public void onNext(@NonNull BaseEntity entity) {
        RegisterEntity registerEntity = (RegisterEntity) entity;
        if (registerEntity.status.equals("200")) {
            v.requestRegister(registerEntity);
        }
    }
}
